home *** CD-ROM | disk | FTP | other *** search
- Path: library.erc.clarkson.edu!rpi!not-for-mail
- From: James Kanze US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de>
- Newsgroups: comp.lang.c++,comp.lang.c++.moderated,comp.sys.hp.hpux
- Subject: Re: [Q] gcc 2.7.2 + STL + HP_UX 9.05 = memory_leak ?
- Date: 26 Mar 1996 19:07:12 -0000
- Organization: unknown
- Sender: cppmods@netlab.cs.rpi.edu
- Approved: Dietmar.Kuehl@uni-konstanz.de
- Message-ID: <4j9f90$5hv@netlab.cs.rpi.edu>
- References: <4j66lu$olu@netlab.cs.rpi.edu>
- NNTP-Posting-Host: netlab.cs.rpi.edu
- X-Original-Date: Tue, 26 Mar 96 18:07:33 +0100
-
- In article <4j66lu$olu@netlab.cs.rpi.edu>
- cvjetko@PROBLEM_WITH_INEWS_GATEWAY_FILE.uni-erlangen.de (Miljenko
- Cvjetko) writes:
-
- |> I was testing storing ptrs in STL container when I found
- |> out a memory-leak in STL implementation in following
- |> example:
-
- |> # include <list.h> // STL list
- |> # include <stdlib.h>
-
- |> class X
- |> {
- |> protected:
- |> list<int> nodes_; // this line causes
- |> // memory leak problems!!!
- |> // under HP_UX 9.05
- |> // not under Borland C/C++ + DOS
- |> };
-
- |> void f()
- |> {
- |> X x1;
- |> }
-
- |> int main()
- |> {
- |> memorymap(1);
- |> f();
- |> memorymap(1); // list is out of scope
- |> return 0;
- |> }
- |> - ------------------------------------------
- |> Result:
-
- |> arenastart : 0
- |> arenaend : 0
- |> # of blocks : 0
- |> # of free blocks : 0
- |> # of used blocks : 0
- |> # of smblk blks : 0
- |> total space used : 0
- |> space in free blocks : 0
- |> space in used blocks : 0
- |> space in smblk blocks : 0
- |> 1073748164: node block 8192
- |> 1073756356: free 1848
-
- |> arenastart : 1073748164
- |> arenaend : 1073758204
- |> # of blocks : 2
- |> # of free blocks : 1
- |> # of used blocks : 1
- |> # of smblk blks : 0
- |> total space used : 10040
- |> space in free blocks : 1848
- |> space in used blocks : 8192
- |> space in smblk blocks : 0
- |> - -------------------------------------------
- |> In addition, this code was compiled under
- |> BC 4.5 and had no memory leak! Am I
- |> misinterpreting memorymap() function call?
- |> Same was with some other containers (set,vector).
- |> Any suggestions?
-
- I doubt that this is significant. I suspect that the missing block is
- some sort of pseudo-static allocated by the implementation. I know,
- for example, that older versions of the Sun compiler would allocate an
- additional block the first time you new'ed a C style array. And most
- implementations will allocate the iobuffer on the first output.
- Neither of these blocks will ever be freed.
-
- What you want to check is to call the function in a loop. If the
- number of unfreed blocks increases with the number of passes in the
- loop, then you've got a real problem. I suspect, however, that you
- will find that you always have one unfreed block, whether you execute
- the loop once, or a 1000 times.
-
- --
- James Kanze Tel.: (+33) 88 14 49 00 email: kanze@gabi-soft.fr
- GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
- Conseils, itudes et rialisations en logiciel orienti objet --
- -- A la recherche d'une activiti dans une region francophone
-
-
- [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
- [ Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm ]
- [ Moderation policy: http://www.connobj.com/cpp/guide.htm ]
- [ Comments? mailto:c++-request@netlab.cs.rpi.edu ]
-